import 'dart:io';

import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';

import 'package:dio/dio.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

import 'package:schedule_plane/module/main/root_page.dart';

import 'module/config/application.dart';
import 'module/config/routes.dart';
import 'common/net/api.dart';
import 'common/net/header_interceptor.dart';
import 'library/networking/http_manager.dart';
import 'library/networking/log_interceptor.dart';

void main() {
  final router = FluroRouter();
  Routes.configureRoutes(router);
  Application.router = router;

  HttpManager().init(baseUrl: Api.getBaseUrl(),
      interceptors: [
        HeaderInterceptor(),
        // CustomLogInterceptor(),
        InterceptorsWrapper(
            onRequest: (RequestOptions options){
              print("\n================== 请求数据 ==========================");
              print("url = ${options.uri.toString()}");
              print("headers = ${options.headers}");
              print("params = ${options.data}");
            },
            onResponse: (Response response){
              print("\n================== 响应数据 ==========================");
              print("code = ${response.statusCode}");
              print("data = ${response.data}");
              print("\n");
            },
            onError: (DioError e){
              print("\n================== 错误响应数据 ======================");
              print("type = ${e.type}");
              print("message = ${e.message}");
              // print("stackTrace = ${e.stackTrace}");
              print("\n");
            }
        )
      ]);
  runApp(MainApp());
}

class MainApp extends StatelessWidget {

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '日程管理',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.yellow,
        // This makes the visual density adapt to the platform that you run
        // the app on. For desktop platforms, the controls will be smaller and
        // closer together (more dense) than on mobile platforms.
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      // home: SCRootPage(title: '日程管理根视图'),  // 采用Fluro来管理视图 配置 onGenerateRoute: Application.router.generator,自动把"/"作为根视图
      // routes: <String, WidgetBuilder>{
      // },
      builder: EasyLoading.init(),
      onGenerateRoute: Application.router.generator,
    );
  }
}

